//Fusion of the 422 Proportion
//Dustin Striplin, Tyler Simrell, Lawrence Grass, and Jacob Hall
//Finished 5/1/13

package model;

import java.util.HashMap;
import java.util.Map;

import net.htmlparser.jericho.Source;

/**
 * The Page Object that is instantiated by the Controller to act as a structure
 * to contain all the data pertinent to each page.
 * @author Jacob Hall, Lawrence Grass
 */

public class PageInfo
{
	/**
	 * The URL identifier for this page.  
	 * To be filled in by the PageParser.
	 */
	private String my_URL = "";
	
	/**
	 * The number of URLs on the current page.
	 * To be filled in by the PageParser.
	 */
	private int num_URLS_on_page = 0;
	
	/**
	 * The time stamp for when the PageInfo Object was created.
	 * To be filled in by the PageParser.
	 */
	private long page_start_time = 0;
	
	/**
	 * The time stamp for when the PageInfo Object was finished being processed
	 * by the parser.
	 * To be filled in by the PageParser.
	 */
	private long page_end_time = 0;
	
	/**
	 * The String representation of all the data pulled from the page 
	 * at the given URL. 
	 * To be filled in by the PageParser.
	 */
	private Source page_content;
	
	/**
	 * The total number of words that are on the current page.
	 * To be filled in by the PageParser.
	 */
	private int num_words_on_page = 0;
	
	/**
	 * The limit on the number of pages that will be processed, specified by the user.
	 * To be filled in by the PageParser.
	 */
	private int page_limit = 0;
	
	/**
	 * The map to associate the specific number of hits for this page per keyword.
	 * Every one of the keywords originally listed by the user should be included
	 * in each submission of this map.  If there is no hit, indicate that with a "0"
	 * To be filled in by the PageParser.
	 */
	private Map<String, Integer> keyword_map = new HashMap<String, Integer>();
	
	/**
	 * The amount of time it took to parse the current page.
	 * To be filled in by the DataGatherer.
	 */
	private long time_to_parse_page = 0;

	/**
	 * The map to associate the running total number of hits per keyword.
	 * To be filled in by the DataGatherer.
	 */
	private Map<String, Integer> keyword_total_hits_map = new HashMap<String, Integer>();

	/**
	 * The map to associate the average number of hits per keyword.
	 * To be filled in by the DataGatherer.
	 */
	private Map<String, Double> keyword_ave_hits_map = new HashMap<String, Double>();

	/**
	 * The running average of the number of words per page at this point.
	 * To be filled in by the DataGatherer.
	 */
	private int ave_words_per_page = 0;
	
	/**
	 * The running average of the number of urls per page at this point.
	 * To be filled in by the DataGatherer.
	 */
	private int ave_urls_per_page = 0;
	
	/**
	 * The running average of the amount of time it takes to parse each page.
	 * To be filled in by the DataGatherer.
	 */
	private String ave_parse_time_per_page = "";

	/**
	 * The running total of the number of pages retrieved at this point.
	 * To be filled in by the DataGatherer.
	 */
	private int total_num_pages_retrieved = 0;

	/**
	 * The running total of the time it has taken to run the program from start to 
	 * the point in time that this page was processed.
	 * To be filled in by the DataGatherer.
	 */
	private String total_running_time = "";

	/**
	 * The running total of the number of words that have been processed from when
	 * the program started until this page was processed. (Used in calculating average)
	 * To be filled in by the DataGatherer.
	 */
	private int running_total_num_words = 0;
	
	/**
	 * The running total of the number of URL's that have been parsed from when the
	 * program started until this page was processed. (Used in calculating average)
	 * To be filled in by the DataGatherer.
	 */
	private int running_total_num_URLs = 0;
	
	/**
	 * The running total of the times to parse each page from when the
	 * program started until this page was processed.  (Used in calculating average)
	 * To be filled in by the DataGatherer.
	 */
	private long running_total_time_to_parse_page = 0;
	
	/**
	 * The page the current url was found on
	 */
	private String parent; 
	
	/**
	 * @return The url that contains the link to the current url
	 */
	public String getParent() {
		return parent;
	}
	
	/**
	 * @param parent the url that contains the link to the current url
	 */
	public void setParent(String parent) {
		this.parent = parent;
	}
	/**
	 * Constructor for the PageInfo Class.
	 * @param the_URL The URL that serves as the name of the PageInfo Object.
	 */
	public PageInfo(final String the_URL)
	{
		my_URL = the_URL;
	}
	
	/**
	 * Returns the URL.
	 * @return my_URL Returns the URL in a String.
	 */
	public String getURL()
	{
		return my_URL;
	}
	
	/**
	 * Sets the URL.
	 * @param the_URL Returns the URL in a String.
	 */
	public void setURL(final String the_URL)
	{
		my_URL = the_URL;
	}
	
	/**
	 * Returns the map correlating the number of hits each keyword got.
	 * @return keyword_map Returns Map collection that contains each keyword and 
	 * 						the corresponding number of hits each keyword got on 
	 * 						that particular page.
	 */
	public Map<String, Integer> getKeyWordMap()
	{
		return keyword_map;
	}
	
	/**
	 * Sets the map correlating the number of hits each keyword got.
	 * @param the_map Returns Map collection that contains each keyword and 
	 * 						the corresponding number of hits each keyword got on 
	 * 						that particular page.
	 */
	public void setKeyWordMap(final Map<String, Integer> the_map)
	{
		keyword_map = the_map;
	}
	
	/**
	 * Returns the number of URL links that were found on the page.
	 * @return num_URLS_on_page Returns the number of URLs on the page.
	 */
	public int getNumURLOnPage()
	{
		return num_URLS_on_page;
	}
	
	/**
	 * Increments the number of URL links that were found on the page by 1.
	 */
	public void incrementNumURLOnPage()
	{
		num_URLS_on_page++;
	}
	
	/**
	 * Sets the number of URL links that were found on the page.
	 * @param the_num_URLS_per_page Returns the number of URLs on the page.
	 */
	public void setNumURLOnPage(final int the_num_URLS_per_page)
	{
		num_URLS_on_page = the_num_URLS_per_page;
	}
	
	/**
	 * Returns the amount of time it took to parse the page.
	 * @return time_to_parse_page The time it took to parse the page.
	 */
	public long getTimeToParsePage()
	{
		return time_to_parse_page;
	}
	
	/**
	 * Sets the amount of time it took to parse the page.
	 * @param the_time_to_parse_page The time it took to parse the page.
	 */
	public void setTimeToParsePage(final long the_time_to_parse_page)
	{
		time_to_parse_page = the_time_to_parse_page;
	}
	
	/**
	 * Returns the time stamp for when the page was instantiated.
	 * @return start_time The time stamp for when the page was instantiated.
	 */
	public long getPageStartTime()
	{
		return page_start_time;
	}
	
	/**
	 * Sets the time stamp for when the page was instantiated.
	 * @param the_start_time The time stamp for when the page was instantiated.
	 */
	public void setPageStartTime(final long the_start_time)
	{
		page_start_time = the_start_time;
	}
	
	/**
	 * Returns the time stamp for when the page was completed.
	 * @return end_time The time stamp for when the page was completed.
	 */
	public long getPageEndTime()
	{
		return page_end_time;
	}
	
	/**
	 * Sets the time stamp for when the page was completed.
	 * @param the_end_time The time stamp for when the page was completed.
	 */
	public void setPageEndTime(final long the_end_time)
	{
		page_end_time = the_end_time;
	}
	
	/**
	 * Returns the page data that was pulled from the given URL to be parsed.
	 * @return page_content The content of the page.
	 */
	public Source getPageContent()
	{
		return page_content;
	}
	
	/**
	 * Sets the page data that was pulled from the given URL to be parsed.
	 * @param the_page_content The content of the page.
	 */
	public void setPageContent(Source the_page_content)
	{
		page_content = the_page_content;
	}
	
	/**
	 * Returns the number of words left on the page after being parsed out.
	 * @return num_words_on_page The number of words on the page.
	 */
	public int getNumWordsOnPage()
	{
		return num_words_on_page;
	}
	
	/**
	 * Sets the number of words left on the page after being parsed out.
	 * @param the_num_words_on_page The number of words on the page.
	 */
	public void setNumWordsOnPage(final int the_num_words_on_page)
	{
		num_words_on_page = the_num_words_on_page;
	}
	
	/**
	 * Returns the limit the user specified as the maximum number of pages to 
	 * retrieve in the webcrawling process.
	 * @return page_limit The page limit.
	 */
	public int getPageLimit()
	{
		return page_limit;
	}
	
	/**
	 * Sets the limit the user specified as the maximum number of pages to 
	 * retrieve in the webcrawling process.
	 * @param the_page_limit The page limit.
	 */
	public void setPageLimit(final int the_page_limit)
	{
		page_limit = the_page_limit;
	}
	
	/**
	 * Returns the running total of pages that have been retrieved up to the point
	 * this page was pulled.
	 * @return total_num_pages_retrieved The number of pages retrieved.
	 */
	public int getNumPagesRetrieved()
	{
		return total_num_pages_retrieved;
	}
	
	/**
	 * Sets the running total of pages that have been retrieved up to the point
	 * this page was pulled.
	 * @param the_num_pages_retrieved The number of pages retrieved.
	 */
	public void setNumPagesRetrieved(final int the_num_pages_retrieved)
	{
		total_num_pages_retrieved = the_num_pages_retrieved;
	}
	
	/**
	 * Returns the average number of words found on each page.
	 * @return ave_words_per_page The average number of words found on each page.
	 */
	public int getAveWordsPerPage()
	{
		return ave_words_per_page;
	}
	
	/**
	 * Sets the average number of words found on each page.
	 * @param the_ave_words_per_page The average number of words found on each page.
	 */
	public void setAveWordsPerPage(final int the_ave_words_per_page)
	{
		ave_words_per_page = the_ave_words_per_page;
	}
	
	/**
	 * Returns the average number of URLs found on each page.
	 * @return ave_urls_per_page The average number of URLs found on each page.
	 */
	public int getAveURLsPerPage()
	{
		return ave_urls_per_page;
	}
	
	/**
	 * Sets the average number of URLs found on each page.
	 * @param the_ave_urls_per_page The average number of URLs found on each page.
	 */
	public void setAveURLsPerPage(final int the_ave_urls_per_page)
	{
		ave_urls_per_page = the_ave_urls_per_page;
	}
	
	/**
	 * Returns the map collection that tracks the average number of hits for
	 * 			each keyword as each page is parsed.
	 * @return keyword_ave_hits_map The map the tracks the average number of hits
	 * 								for each given keyword.
	 */
	public Map<String, Double> getKeywordAveHitsMap()
	{
		return keyword_ave_hits_map;
	}
	
	/**
	 * Sets the map collection that tracks the average number of hits for
	 * 			each keyword as each page is parsed.
	 * @param the_keyword_ave_hits_map The map the tracks the average number of hits
	 * 								for each given keyword.
	 */
	public void setKeywordAveHitsMap(final Map<String, Double> the_keyword_ave_hits_map)
	{
		keyword_ave_hits_map = the_keyword_ave_hits_map;
	}
	
	/**
	 * Returns the map collection that keeps a running total of the number of hits
	 * 			each keyword has gotten.
	 * @return keyword_total_hits_map The map the tracks the total number of hits
	 * 								for each given keyword.
	 */
	public Map<String, Integer> getKeywordTotalHitsMap()
	{
		return keyword_total_hits_map;
	}
	
	/**
	 * Sets the map collection that keeps a running total of the number of hits
	 * 			each keyword has gotten.
	 * @param the_keyword_total_hits_map The map the tracks the total number of hits
	 * 								for each given keyword.
	 */
	public void setKeywordTotalHitsMap(final Map<String, Integer> the_keyword_total_hits_map)
	{
		keyword_total_hits_map = the_keyword_total_hits_map;
	}
	
	/**
	 * Returns the average time it has taken to this point to parse the pages.
	 * @return ave_parse_time_per_page The average time it has taken to parse the pages.
	 */
	public String getAveParseTimePerPage()
	{
		return ave_parse_time_per_page;
	}
	
	/**
	 * Sets the average time it has taken to this point to parse the pages.
	 * @param the_ave_parse_time_per_page The average time it has taken to parse the pages.
	 */
	public void setAveParseTimePerPage(final String the_ave_parse_time_per_page)
	{
		ave_parse_time_per_page = the_ave_parse_time_per_page;
	}
	
	/**
	 * Returns the total accumulated time it has taken to run the program 
	 * to this point.
	 * @return total_running_time The total time is has taken to run the program.
	 */
	public String getTotalRunTime()
	{
		return total_running_time;
	}
	
	/**
	 * Sets the total accumulated time is has taken to run the program to 
	 * this point.
	 * @param the_total_running_time The total time is has taken to run the program.
	 */
	public void setTotalRunTime(final String the_total_running_time)
	{
		total_running_time = the_total_running_time;
	}
	
	/**
	 * Returns the running total of the number of words processed in all the pages combined.
	 * @return running_total_num_words The total number of words processed to this point.
	 */
	public int getTotalNumWords()
	{
		return running_total_num_words;
	}
	
	/**
	 * Sets the running total of the number of words processed in all the pages combined.
	 * @param the_running_total_num_words The total number of words processed to this point.
	 */
	public void setTotalNumWords(final int the_running_total_num_words)
	{
		running_total_num_words = the_running_total_num_words;
	}
	
	/**
	 * Returns the running total of the number of URLs processed in all the pages combined.
	 * @return running_total_num_URLs The total number of URLs processed to this point.
	 */
	public int getTotalNumURLs()
	{
		return running_total_num_URLs;
	}
	
	/**
	 * Sets the running total of the number of URLs processed in all the pages combined.
	 * @param the_running_total_num_URLs The total number of URLs processed to this point.
	 */
	public void setTotalNumURLs(final int the_running_total_num_URLs)
	{
		running_total_num_URLs = the_running_total_num_URLs;
	}
	
	/**
	 * Returns the running total of the time it has taken to parse the pages processed in 
	 * all the pages combined.
	 * @return running_total_time_to_parse_page The total time it has taken to parse the pages
	 * 											 processed to this point.
	 */
	public long getTotalTimeToParsePages()
	{
		return running_total_time_to_parse_page;
	}
	
	/**
	 * Sets the running total of the time it has taken to parse the pages processed in 
	 * all the pages combined.
	 * @param the_running_total_time_to_parse_page The updated total time it has taken to parse
	 * 												the pages processed to this point.
	 */
	public void setTotalTimeToParsePages(final long the_running_total_time_to_parse_page)
	{
		running_total_time_to_parse_page = the_running_total_time_to_parse_page;
	}
	
}
